//https://leetcode.cn/problems/single-number-iii/

class Solution {
public:
    vector<int> singleNumber(vector<int>& nums) {
        int xorResult = 0;
        for (int num : nums) {
            xorResult ^= num;
        }
        int rightmostSetBit = (xorResult == INT_MIN ? xorResult : xorResult & (-xorResult));
        int num1 = 0, num2 = 0;

        for (int num : nums) {
            if (num & rightmostSetBit) {
                num1 ^= num;
            }
            else {
                num2 ^= num;
            }
        }

        return { num1, num2 };
    }
};